package utils;

import java.util.List;

import models.Cordinate;
import models.User;
import models.UserCity;
import models.UserPlace;
import models.UserPlaceType;


import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

public class ApplicationMessages {
      
	public JsonObject createAddCityUserSuccessMessage(UserCity userCity,User user){
	   JsonObject message = new JsonObject();
	  if(userCity != null){
		  message.addProperty("success", true);
		  message.addProperty("cityId",userCity.getId() );
		  message.addProperty("userId", user.getFacebookID());
		  message.addProperty("message", "the " + userCity.getCityName() + " is added");
	  }else{
		  message.addProperty("success", false);
		  message.addProperty("message", "the city  can not added");
	  }
	  return message;
	}
	public JsonObject userHasAlreadyPlaceMessage(UserPlace userPlace,UserCity userCity ){
		   JsonObject message = new JsonObject();
		  if(userPlace != null){
			  message.addProperty("success", true);
			  message.addProperty("placeId",userPlace.getId() );
			  message.addProperty("cityId", userCity.getId());
			  message.addProperty("message", "the " + userPlace.getPlaceName() + " is already in the system");
		  }else{
			  message.addProperty("success", false);
			 // message.addProperty("placeId", userPlace.getId());
			  message.addProperty("message", "the place is not in the system");
		  }
		  return message;
		}
	public JsonObject addUserPlaceSuccesfullMessage(UserPlace userPlace,UserCity userCity ){
		   JsonObject message = new JsonObject();
		  if(userPlace != null){
			  message.addProperty("success", true);
			  message.addProperty("placeId",userPlace.getId() );
			  message.addProperty("cityId", userCity.getId());
			  message.addProperty("message", "the " + userPlace.getPlaceName() + " is added succesfully");
		  }else{
			  message.addProperty("success", false);
			 // message.addProperty("placeId", userPlace.getId());
			  message.addProperty("message", "the place is not added");
		  }
		  return message;
		}

	public JsonObject creategeUserPlaceOfCityMessage(List<UserPlace> userPlaces){
		JsonObject message = new JsonObject();
		if(userPlaces == null || userPlaces.size() < 1){
			message.addProperty("success",true);
			message.addProperty("size",0);
		}else {
			message.addProperty("success", true);
			message.addProperty("size",userPlaces.size());
			JsonArray placeArray = new JsonArray();
			
			for(UserPlace place :userPlaces){
				JsonObject onePlaceJson = new JsonObject();
				JsonArray userPlaceTypeArrayJson = new JsonArray();
			    onePlaceJson.addProperty("placeId", place.getId());
			    onePlaceJson.addProperty("placeName",place.getPlaceName());
			    Cordinate cordinate = place.getPlaceInfo().getCordinate();
			    onePlaceJson.addProperty("latitude",cordinate.getLatitude());
			    onePlaceJson.addProperty("longitude",cordinate.getLongitude());
			    List<UserPlaceType> userPlaceTypes = place.getUserPlaceTypes();
			    for(UserPlaceType placeType : userPlaceTypes){
			    	JsonObject placeTypeJson = new JsonObject();
			    	placeTypeJson.addProperty("placeType", placeType.getPlaceType());
			    	userPlaceTypeArrayJson.add(placeTypeJson);
			    }
			    onePlaceJson.add("placeTypes", userPlaceTypeArrayJson);
			    placeArray.add(onePlaceJson);	
			}
			message.add("places", placeArray);
		}
	 return message;
	}
}
